#include "nav_view.h"

#include <view.h>
#include <macro.h>
#include <types.h>
#include <config.h>
#include <device/device.h>
#include <msg/msg.h>

nav_view::nav_view():view(){
	left=0;
	top=0;
	right=0;
	bottom=0;
	enable=0;
	visiable=0;
};

nav_view::nav_view(int a,int b,int w,int h,bool e):view(a,b,w,h,e){

	left=(w-NAV_WIDTH)/2;
	top=(h-NAV_HEIGHT)/2;
	right=left+NAV_WIDTH;
	bottom=top+NAV_HEIGHT;
	enable=e;
	visiable=0;
};

nav_view::~nav_view(){

};
/*
int nav_view::repaint(){

};
*/
int nav_view::init(int a,int b,int w,int h,bool e){

	left=(w-NAV_WIDTH)/2;
	top=(h-NAV_HEIGHT)/2;
	right=left+NAV_WIDTH;
	bottom=top+NAV_HEIGHT;
	enable=e;
};


int nav_view::show(){
	int ret=0;

	int i,j;

	if(!backbits.empty())return 0;

	for(i=top;i<=bottom;i++)
	for(j=left;j<=right;j++)
		backbits.push_back(device::bitbuf[i*device::width+j]);

	//device::draw_rect(left,top,right,bottom,0xff);	
	device::fill_rect(left,top,right,bottom,0xff);	

	visiable=1;
	return ret;
};

int nav_view::hide(){
	int ret=0;

	int i,j;
	if(backbits.empty())return 0;

	#ifdef COLOR32
        list<unsigned int>::iterator k;
        #else
        list<unsigned short>::iterator k;
	#endif

	k=backbits.begin();


	for(i=top;i<=bottom;i++)
	for(j=left;j<=right;j++){
		device::bitbuf[i*device::width+j]=*k;
		k++;
	}

	visiable=0;
	backbits.clear();
	return ret;
};

int nav_view::key_down_proc(msg *m){
	int ret=0; 
	switch(m->key){
                case BTN_UP:
                        //device::draw_string(UCHAR("BTNUP"),100,100,0xff);
			char name[128];
			MKRES(name,"4.jpg");
			printf("name:%s\n",name);
			device::draw_jpg(0,0,name);
                break;
                case BTN_DOWN:
                        device::draw_string(UCHAR("BTNDOWN"),100,150,0xff);
                break;
                case BTN_NEXT:
                        device::draw_string(UCHAR("BTNNEXT"),100,200,0xff);
                break;
                case BTN_PRV:
                        device::draw_string(UCHAR("BTNPRV"),100,250,0xff);
                break;
                case BTN_OK:
                        device::draw_string(UCHAR("BTNOK"),100,300,0xff);
                break;
                case BTN_UI:
			if(visiable)
                        	hide();
			else show();
                break;
		default:

		break;
        }
	return ret;
};

